package com.yulebaby.callsenter.ui.activity;

import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.event.EventFactory;
import com.yulebaby.callsenter.ui.base.BaseActivity;
import com.yulebaby.callsenter.ui.fragment.CustomerFragment;
import com.yulebaby.callsenter.ui.fragment.DailyFragment;
import com.yulebaby.callsenter.ui.fragment.InternationalWaterFragment;
import com.yulebaby.callsenter.ui.fragment.RecordFragment;
import com.yulebaby.callsenter.ui.view.BottomBar;
import com.yulebaby.callsenter.ui.view.BottomBarTab;
import com.yulebaby.callsenter.utils.PhoneUtil;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import me.yokeyword.fragmentation.SupportFragment;

public class MainActivity extends BaseActivity {

    @BindView(R.id.bottom_bar)
    BottomBar mBottomBar;

    public static final int FIRST = 0;
    public static final int SECOND = 1;
    public static final int THIRD = 2;
    public static final int FOUR = 3;

    private SupportFragment[] mFragments = new SupportFragment[4];

    @Override
    protected int initLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        PhoneUtil.startServices(); //开启服务
        mFragments[FIRST] = CustomerFragment.newInstance();//客户
        mFragments[SECOND] = InternationalWaterFragment.newInstance();//公海
        mFragments[THIRD] = RecordFragment.newInstance();//记录
        mFragments[FOUR] = DailyFragment.newInstance();//日报
        loadMultipleRootFragment(R.id.fl_main, FIRST,
                mFragments[FIRST],
                mFragments[SECOND],
                mFragments[THIRD],
                mFragments[FOUR]);
        initBottomBar();
    }

    /**
     * 初始化底部点击BUtton
     */
    private void initBottomBar() {
        mBottomBar.addItem(new BottomBarTab(this, R.drawable.tab_icon_customer, "客户"))
                .addItem(new BottomBarTab(this, R.drawable.tab_icon_returnvisit, "公海"))
                .addItem(new BottomBarTab(this, R.drawable.tab_icon_record, "记录"))
                .addItem(new BottomBarTab(this, R.drawable.tab_icon_daily, "日报"));
        mBottomBar.setOnTabSelectedListener(new BottomBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position, int prePosition) {
                showHideFragment(mFragments[position], mFragments[prePosition]);
            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {
                EventBus.getDefault().post(EventFactory.CreateTabSelectedEvent(position));
            }
        });
    }

}
